<template>
    <div>
        <div class="header mytask_head"><img src="../../images/left.png" alt="" v-on:click="$router.back(-1)">{{ title
            }}
        </div>
        <div class="mutlist" style="overflow-y: scroll;background: #E6E6E6;" :style="{ height: screen }">
            <mt-loadmore :top-method="loadTop" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded"
                         :auto-fill="false" ref="loadmore">
                <div class="W_723 clearfix">
                    <div class="goodWokrs clearfix" v-for="task in tasks" v-on:click="target(task.work_user_id, task.job.type.tag)">
                        <img src="../../images/questionIcon.png" alt="" class="questionIcon"
                             v-if="task.question_list && task.question_list != 'NULL'">
                        <div class="titleH3 fl">
                            <!--<h3 class="Bigcolor">{{ get(task,'job.type.text') }}</h3>-->
                            <img :src="get(task,'job.image.url')" v-if="task.job.image.url.indexOf('http') != -1"/>
                            <img :src="qiniu_domain + get(task,'job.image.url')" v-else/>
                        </div>
                        <div class="fr_workText fl">
                            <div class="Numlists">
                                <div class="linder">
                                    <div class="titleNewimg">
                                        <img src="../../images/homese1.png"/>
                                        <span>{{ get(task,'goods.goods_title')}}</span>
                                    </div>
                                    <!--<p class="listName">-->
                                    <!--</p>-->
                                    <div class="workNeed">
                                        <!--<span>{{  }}</span>-->
                                        <span v-if="task.job.type.tag != 'custom'">{{ get(task,'items') }}</span>
                                        <span v-else>领取后显示任务要求</span>
                                    </div>
                                    <div class="moneyYmoney">
                                        <span>￥{{ task.user_money }}</span>
                                        <em class="reward" v-if="task.job.reward">
                                            <ul>
                                                <li>加赏</li>
                                                <!-- <li>加赏{{ task.job.reward.job_meta_value }}</li> -->
                                            </ul>
                                        </em>
                                        <img src="@/images/privilege-jifen.png" style="margin-left: 0.5rem"/>
                                        <span v-if="task.job.sort == '1000000000'">{{ finish_work_credit }}</span>
                                        <span v-else>{{credit_multiple }}</span>
                                        <span class="tuijian" v-if="task.job.sort != '1000000000'">推荐</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </mt-loadmore>

        </div>
        <div class="fixed_color"></div>
    </div>
</template>

<script>
    import api from '../../utils/api';
    import _ from 'lodash';

    export default {
        name: 'MyTasksList',
        data() {
            return {
                mescroll: null,
                page: 1,
                status: this.$route.query.status,
                tasks: [],
                title: this.$route.query.name,
                allLoaded: false,
                qiniu_domain: localStorage.getItem('qiniu_domain'),
                screen: 0,
                credit_multiple: false, // 推荐积分
                finish_work_credit: false, // 积分
                sort_credit: false, //是否是推荐任务
                platform_id: this.$route.query.platform_id
            }
        },
        created() {
            this.credit_multiple = parseInt(localStorage.getItem('credit_multiple'))
            this.finish_work_credit = parseInt(localStorage.getItem('finish_work_credit'))
        },
        mounted() {
            new Swiper('.swiper1', {
                slidesPerView: 5,
                onTransitionEnd: function (swiper) {
                    if (swiper.progress == 1) {
                        swiper.activeIndex = swiper.slides.length - 1
                    }
                }
            });
            this.loadTop()
            let topHeight = document.getElementsByTagName('body')[0].offsetHeight
            this.screen = 17 + 'rem';


            // this.anumber();
        },
        methods: {
            // async anumber(){
            //     await api.request('/workAuditNum', 'get', {}).then(function (res) {
            //         localStorage.setItem("tbworkAuditNumber",res.data.data.taobao.num);
            //         localStorage.setItem("jdworkAuditNumber",res.data.data.jingdong.num);
            //         localStorage.setItem("pddworkAuditNumber",res.data.data.pingduoduo.num);
            //     })
            // },
            get(object, path, defaultValue) {
                return _.get(...arguments);
            },
            target(work_id, type) {
                var path = `/task/detail/${work_id}`
                if(type.indexOf('custom') != -1){
                    path = `/task/detailCustom/${work_id}`
                }
                this.$router.push({
                    path: path,
                })
            },
            loadBottom() {
                api.request('/myWorksList', 'get', {
                    status: this.status,
                    page: this.page + 1,
                    platform_id: this.platform_id
                }).then((resp) => {
                    let arr = resp.data.data.data
                    if (arr.length >= 1) {
                        this.page = this.page + 1;
                        this.tasks = this.tasks.concat(arr);
                        this.$refs.loadmore.onBottomLoaded();
                    } else {
                        this.$refs.loadmore.onBottomLoaded();
                    }

                })
            },
            loadTop() {
                api.request('/myWorksList', 'get', {status: this.status, page: 1, platform_id: this.platform_id}).then((resp) => {
                    let arr = resp.data.data.data
                    this.tasks = []
                    this.page = 1
                    this.tasks = arr;
                    this.$refs.loadmore.onTopLoaded();
                })

            },

        }
    }
</script>
<style scoped>


    .W_723 {
        overflow: auto;
        padding: .5rem 0;
    }
    .fixed_color {
        background: #E6E6E6;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: -1;
    }
</style>
